package com.herenit.beijing.dh2011.dto;

import java.io.Serializable;

public class PageObject implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * 是否有上一页
     */
    private boolean hasPrePage;
    /**
     * 是否有下一页
     */
    private boolean hasNextPage;
    /**
     * 每页数据量
     */
    private int pageSize = 25;
    /**
     * 总页数
     */
    private int totalPage = 1;
    /**
     * 第几页
     */
    private int pageNo = 1;
    /**
     * 开始数据数
     */
    private int beginIndex = 0;
    /**
     * 总数据数
     */
    private long totalRecord = 0;

    public int getBeginIndex(int everyPage, int currentPage) {
        return (currentPage - 1) * everyPage;
    }

    public int getBeginIndex(int currentPage) {
        return getBeginIndex(pageSize, currentPage);
    }

    public int getTotalPage(int everyPage, long totalRecords) {

        if (totalRecords % everyPage == 0) {
            totalPage = (int) (totalRecords / (long) everyPage);
        } else {
            totalPage = (int) (totalRecords / (long) everyPage) + 1;
        }
        return totalPage;
    }

    public int getTotalPage(int totalRecords) {

        return getTotalPage(pageSize, totalRecords);
    }

    public int getTotalPage() {

        return getTotalPage(pageSize, totalRecord);
    }

    public boolean hasPrePage(int currentPage) {
        return currentPage == 1 ? false : true;
    }

    public boolean hasNextPage(int currentPage, int totalPage) {
        return currentPage == totalPage || totalPage == 0 ? false : true;
    }

    public boolean isHasPrePage() {
        return hasPrePage;
    }

    public void setHasPrePage(boolean hasPrePage) {
        this.hasPrePage = hasPrePage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageNo() {
        if (pageNo < 1) {
            return 1;
        }
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getBeginIndex() {
        return getBeginIndex(pageSize, getPageNo());
    }

    public void setBeginIndex(int beginIndex) {
        this.beginIndex = beginIndex;
    }

    public long getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(long totalRecord) {
        this.totalRecord = totalRecord;
    }

    @Override
    public String toString() {
        return "PageObject{" + "hasPrePage=" + hasPrePage + ", hasNextPage=" + hasNextPage + ", pageSize=" + pageSize + ", totalPage=" + totalPage + ", pageNo=" + pageNo + ", beginIndex=" + beginIndex + ", totalRecord=" + totalRecord + '}';
    }
    
    
}
